package com.lqd.mall.system.controller;

import com.lqd.mall.basis.response.CommonResult;
import com.lqd.mall.basis.response.Result;
import com.lqd.mall.interaction.system.SysDeptEntity;
import com.lqd.mall.jpa.controller.BaseController;
import com.lqd.mall.log.annotation.Log;
import com.lqd.mall.log.enums.BusinessType;
import com.lqd.mall.security.annotation.RequiresPermissions;
import com.lqd.mall.system.SysDeptControllerApi;
import com.lqd.mall.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 零起点
 * @create 2022-03-26 17:58
 */
@RestController
public class SysDeptController extends BaseController implements SysDeptControllerApi {


    @Autowired
    ISysDeptService sysDeptService;


    @Override
    @RequiresPermissions("system:dept:list")
    public Result<List<SysDeptEntity>> list(SysDeptEntity entity) {
        List<SysDeptEntity> entities = sysDeptService.listSysDeptEntity(entity);
        return Result.SUCCESS(entities);
    }

    @Override
    public Result<List<SysDeptEntity>> treeselect(SysDeptEntity entity) {
        List<SysDeptEntity> treeselect = sysDeptService.treeselect(entity);
        return Result.SUCCESS(treeselect);
    }

    @Override
    @Log(title = "添加部门信息", businessType = BusinessType.INSERT)
    public CommonResult save(SysDeptEntity entity) {
        return result(sysDeptService.save(entity));
    }

    @Override
    public CommonResult upateSysDeptEntity(SysDeptEntity entity) {
        return   result(sysDeptService.upateSysDeptEntity(entity));
    }

    @Override
    public Result<SysDeptEntity> findSysDeptEntitById(Long deptId) {
        SysDeptEntity sysDeptEntity = sysDeptService.selectById(deptId);
        return Result.SUCCESS(sysDeptEntity);
    }

    @Override
    public CommonResult deleteSysDeptEntitById(Long deptId) {
        return result(sysDeptService.deleteSysDeptEntitById(deptId));
    }

    @Override
    public Result<List<SysDeptEntity>> excludeChild(Long deptId) {
        List<SysDeptEntity> sysDeptList =  sysDeptService.excludeChild(deptId);
        return Result.SUCCESS(sysDeptList);
    }
}
